#include <vtkForceDirectedLayoutStrategy.h>
#include <vtkGraphLayoutView.h>
#include <vtkMutableUndirectedGraph.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>

#include <vtkArcSource.h>
#include <vtkPolyDataMapper.h>
#include "vtkPolygon.h"
#include "vtkProperty.h"

#include "vtkLookupTable.h"
#include "vtkMinimalStandardRandomSequence.h"
#include "vtkCellData.h"
#include "vtkSphereSource.h"
#include "vtkTubeFilter.h"
#include "vtkLineSource.h"
#include "vtkSphereSource.h"
#include <vtkProperty.h>
#include "vtkCamera.h"
#include "vtkCameraActor.h"
#include "vtkAppendPolyData.h"
#include "vtkPointCloudFilter.h"
#include "vtkPointSource.h"
#include "vtkVertexGlyphFilter.h"
#include "vtkElevationFilter.h"
#include "vtkGlyph3D.h"
#include "vtkGlyph3DMapper.h"
#include "vtkVertex.h"
#include "vtkPointData.h"
#include "vtkDoubleArray.h"
#include "vtkTupleInterpolator.h"
#include "vtkSphereTreeFilter.h"
#include "vtkProjectSphereFilter.h"

#include "vtkInteractorStyleTrackballCamera.h"


int main(int, char*[]) {


    vtkNew<vtkCellArray> allPolygons;
    vtkNew<vtkPoints> allPoints;
    vtkNew<vtkPolyData> polygonPolyData;

    // 终极方法(vtkGlyph3DMapper is gpu of vtkGlyph3D)：

    vtkNew<vtkIntArray> array1;
    array1->SetName("Array1");

    for (int i = 0; i < 3; ++i) {
        allPoints->InsertNextPoint(i, 0, 0);
    }
    polygonPolyData->SetPoints(allPoints);

    //    颜色
    vtkNew<vtkUnsignedCharArray> colorList;
    colorList->SetName("Color");
    colorList->SetNumberOfComponents(4);
    colorList->SetNumberOfTuples(polygonPolyData->GetNumberOfPoints());
    for (int i = 0; i < polygonPolyData->GetNumberOfPoints(); i++) {
        double color[4] = {255, 0, 0, 255};
        colorList->InsertTuple(i, color);
    }
//    polygonPolyData->GetPointData()->SetScalars(cellData);
    polygonPolyData->GetPointData()->AddArray(colorList);
//    polygonPolyData->GetPointData()->SetActiveScalars("Color");

    // 大小 - 修改失败！！！
    vtkNew<vtkDoubleArray> radiusList;
    radiusList->SetName("Radius");
    radiusList->SetNumberOfValues(polygonPolyData->GetNumberOfPoints());
    for (int i = 0; i < polygonPolyData->GetNumberOfPoints(); i++) {
]        radiusList->InsertNextValue(i);
    }
    polygonPolyData->GetPointData()->AddArray(radiusList);
    polygonPolyData->GetPointData()->SetActiveScalars("Radius");


    vtkNew<vtkSphereSource> sphere;
    sphere->SetRadius(0.5);

    vtkNew<vtkGlyph3DMapper> mapper;
    mapper->SetInputData(polygonPolyData);
    mapper->SetSourceConnection(sphere->GetOutputPort());
//    mapper->ScalarVisibilityOff();
//    mapper->ScalingOff();
//    mapper->SetColorModeToMapScalars();
//    mapper->ScalingOn();
    mapper->ScalarVisibilityOn();
//    mapper->SetScaleModeToScaleByMagnitude();

// 并不能修改大小
//    mapper->SetScaleArray("Radius");
//    const char *mode1 = mapper->GetScaleModeAsString();
//    mapper->SetScaleMode(2);
//    mapper->Update();




//    vtkNew<vtkPointSource> point;
//    point->SetNumberOfPoints(1);
//    point->SetRadius(0.5);

//    vtkNew<vtkGlyph3D> glyph3D;
//    glyph3D->SetSourceConnection(sphere->GetOutputPort());
//    glyph3D->ScalingOff();
//    glyph3D->SetInputData(polygonPolyData);
//    glyph3D->Update();

//    vtkNew<vtkPolyDataMapper> mapper;
//    mapper->SetInputConnection(glyph3D->GetOutputPort());


//    vtkNew<vtkVertexGlyphFilter> glyphFilter;
//    glyphFilter->SetInputData(polygonPolyData);
//    glyphFilter->Update();
//
//    vtkNew<vtkElevationFilter> elevationFilter;
//    elevationFilter->SetInputConnection(glyphFilter->GetOutputPort());
////    elevationFilter->SetLowPoint(0, 0, 0);
////    elevationFilter->SetHighPoint(0, 0, 20);

//    vtkNew<vtkPolyDataMapper> mapper;
////    mapper->SetInputData(polygonPolyData);
//    mapper->SetInputConnection(elevationFilter->GetOutputPort());


    vtkNew<vtkActor> actor;
    actor->SetMapper(mapper);
//    actor->GetProperty()->SetColor(0, 244, 0);
//    actor->GetProperty()->EdgeVisibilityOn();
//    actor->GetProperty()->SetColor(255, 1, 1);


    vtkNew<vtkRenderer> renderer;
//    renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
//    renderer->ResetCamera();
//    renderer->GetActiveCamera()->Zoom(1.5);
//    renderer->GetActiveCamera()->SetPosition(0, 0, 2);

    renderer->AddActor(actor);

//    renderer->AddActor(cylinderActor->ShallowCopy());

    vtkNew<vtkRenderWindow> renderWindow;
    renderWindow->SetSize(300, 300);
    renderWindow->AddRenderer(renderer);
    renderWindow->SetWindowName("Cylinder");

    vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
    renderWindowInteractor->SetRenderWindow(renderWindow);

    renderWindow->Render();
    renderWindowInteractor->Start();

    return EXIT_SUCCESS;
}